package com.jianggy.spi;



import java.util.Iterator;
import java.util.ServiceLoader;
import java.sql.Driver;

/**
 * Hello world!
 *
 */
public class App 
{
    public static void main( String[] args )
    {
        ServiceLoader loader = ServiceLoader.load(Driver.class);
        Iterator<Driver> iterator = loader.iterator();
        String targetName = "com.mysql.jdbc.Driver";
        boolean isExist = false;
        while (iterator.hasNext()){
            Driver driver = iterator.next();
            System.out.println(driver.getClass().getName());
            if (driver.getClass().getName().equals(targetName)){
                isExist = true;
            }
        }
       try {
           Class clazz = Class.forName(targetName);
           Driver driver = (Driver) clazz.newInstance();
           System.out.println("加载的类名称为："+driver.getClass().getName());
       }catch (Exception e){
           e.printStackTrace();
       }

    }
}
